<?php

require_once 'Entity.php';

define ('STAFF_TYPE_WAITER', 0);
define ('STAFF_TYPE_WAITER_ONLINE', 1);
define ('STAFF_TYPE_CHEF', 2);

/**
 * Personel.
 *
 * @author Rafał Cupał
 * @author Przemysław Furmańczyk
 */
class Staff extends Entity {
    protected $user = null;
    protected $restaurant = null;
    protected $type = null;
    
    public function __construct($dataBase) {
        parent::__construct($dataBase, 'staff');
    }
    
    public function getUserId() {
        return $this->user;
    }
    
    public function setUserId($newUserId) {
        $this->user = (int)$newUserId;
    }
    
    public function getRestaurantId() {
        return $this->restaurant;
    }
    
    public function setRestaurantId($newRestaurantId) {
        $this->restaurant = (int)$newRestaurantId;
    }
    
    public function getType() {
        return $this->type;
    }
    
    public function setType($newType) {
        $this->type = (int)$newType;
    }
    
    public function load($rowData) {
        $this->id = $rowData['id'];
        $this->getRowData($rowData, $this->user, 'user');
        $this->getRowData($rowData, $this->restaurant, 'restaurant');
        $this->getRowData($rowData, $this->type, 'type');
    }
    
    public function save() {
        $rowData = array();
      
        $this->setRowData($rowData, $this->user, 'user');
        $this->setRowData($rowData, $this->restaurant, 'restaurant');
        $this->setRowData($rowData, $this->type, 'type');
        
        if ($this->id > 0) {
            $this->dataBase->update($this->tableName, $rowData, 
                    'id = ' . $this->id);
        }
        else {
            $this->dataBase->insert($this->tableName, $rowData);
            $this->id = $this->dataBase->lastInsertId();
        }
    }
}
